<template>
  <div class="collectAdd">
    <div class="collectAddMain">
      <el-form :model="formDataInfo" :rules="rules" ref="formInfo" class="form-box">
        <div><img :src="iconMini1" alt=""> 节点信息</div>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="节点名称：" :label-width="formLabelWidth" prop="tableName">
              <el-input v-model="formDataInfo.tableName" placeholder="" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="请选择节点：" :label-width="formLabelWidth" prop="name">
              <el-select v-model="formDataInfo.name" placeholder="请选择分类">
                <el-option v-for="item in typecationList" :key="item.id" :label="item.authName" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="">
              <el-button type="primary" class="btnwidth120" @click="_addNode" :disabled="isSave"><i
                  class="el-icon-plus"></i> 添加节点</el-button>
              <el-button type="primary" v-show="isSave" @click="_saveNode"><i class="el-icon-circle-check"></i>
                保存</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-form :model="formDataNode" :rules="rules" ref="formInfo" class="form-box form-box-1"
        :class="isSave ? 'form-box-2' : ''">
        <el-row :gutter="20">
          <el-col :span="6" v-if="isSave">
            <el-form-item label="节点名称" prop="name" :label-width="formLabelWidth">
              <el-input v-model="formDataNode.name" placeholder="" :disabled="!isSave"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="角色" prop="role" :label-width="formLabelWidth">
              <el-input v-model="formDataNode.role" placeholder="" :disabled="!isSave"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="作战要素" prop="point" :label-width="formLabelWidth">
              <el-input v-model="formDataNode.point" placeholder="" :disabled="!isSave"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="高度" prop="height" :label-width="formLabelWidth">
              <el-input v-model="formDataNode.height" placeholder="" :disabled="!isSave">
                <template slot="append">KM</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="经度" prop="lon" :label-width="formLabelWidth">
              <el-input v-model="formDataNode.lon" placeholder="" :disabled="!isSave">
                <template slot="append">°E</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="纬度" prop="lat" :label-width="formLabelWidth">
              <el-input v-model="formDataNode.lat" placeholder="" :disabled="!isSave">
                <template slot="append">°N</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="图标" prop="icon" :label-width="formLabelWidth" style="margin-bottom: 0;">
              <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                <img v-if="imageUrl" :src="imageUrl" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div><img :src="iconMini1" alt=""> 数据采集表</div>
      <el-row :gutter="20" class="form-item-box">
        <el-col :span="6">
          <div class="collectBtnBox">
            <img :src="collectIcon" alt="">
            <el-button type="primary" style="width: 150px;"><i class="el-icon-plus"></i> 添加数据采集表</el-button>
          </div>
        </el-col>
        <el-col :span="18">
          <el-table border ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
            :row-class-name="tableRowClassName" height="calc(100vh - 610px)">
            <!-- 调整表格列的prop属性与数据字段对应 -->
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column type="index" width="50" label="序号"></el-table-column>
            <el-table-column label="名称" prop="dataName" align="left"></el-table-column>
            <el-table-column prop="dataFrom" label="表名" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="storageSize" label="创建人" align="left" width="150">
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间" align="left" width="250">
            </el-table-column>
            <el-table-column prop="address" label="操作" align="left" width="100px">
              <template slot-scope="scope">
                <el-button type="text" @click="preview(scope.row)">详情</el-button>
                <el-button type="text" @click="del(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="table-pagination">
            <el-pagination style="text-align: right; padding: 20px 10px 10px 10px"
              :current-page.sync="searchParams.pageNo" @current-change="_page" @size-change="_pageSize"
              :page-sizes="[10, 20, 30, 40]" :page-size="searchParams.pageSize"
              layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="btnBox">
      <el-button type="primary" @click="submit" class="submitBtn">提交</el-button>
      <el-button type="primary" @click="cancel" plain>取消</el-button>
    </div>
  </div>
</template>
<script>
import { UUID } from '@/assets/js/uuid.js'
import iconMini1 from '@/assets/images/iconMini1.png'
import collectIcon from '@/assets/images/collectIcon.png'
import { del } from 'vue'
export default {
  components: {},
  props: {
    currentRowData: {
      type: Object,
      default: () => ({})
    },
    pageStatus: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      iconMini1,
      collectIcon,
      isSave: false,
      formDataInfo: {},
      formDataNode: {},
      imageUrl: '',
      formLabelWidth: '120px',
      formLabelWidth1: '85px',
      rules: {
        tableName: [
          { required: true, message: "请填写表名", trigger: "blur" }
        ],
        name: [
          { required: true, message: "请填写名称", trigger: "blur" }
        ],
        type: [
          { required: true, message: "请选择分类", trigger: "blur" }
        ],
        classification: [
          { required: true, message: "请选择密级", trigger: "blur" }
        ],

      },
      tableData: [{
          dataName: '数据表1',
          dataFrom: '表1',
          createTime: '2020-01-01 00:00:00',
          createUser: '张三',
          storageSize: 1024,
          fileSize: 1,
          address: 'http://www.baidu.com'
        },
        {
          dataName: '数据表2',
          dataFrom: '表3',
          createTime: '2020-01-01 00:00:00',
          createUser: '张三',
          storageSize: 1024,
          fileSize: 1,
          address: 'http://www.baidu.com'
        },],
      searchParams: {
        pageNo: 1,
        pageSize: 10
      },
      total:0,

      typecationList: [
        {
          id: '1',
          name: '力量构建'
        },
        {
          id: '2',
          name: '力量构建'
        },
        {
          id: '3',
          name: '力量构建'
        },
      ],
    }
  },
  created() {
    this.getTabelPage()
  },
  computed: {},
  mounted() {

  },
  methods: {
    //提交
    submit() {
      this.$emit('nodeIndex', { state: false });
    },
    //取消
    cancel() {
      this.$emit('nodeIndex', { state: false });
    },

    //添加节点
    _addNode() {
      this.isSave = true
    },
    //保存节点
    _saveNode() {
      this.isSave = false
    },
    //删除
    _delField(index) {
      this.form.fieldBoxList.splice(index, 1);
    },
    //上传图片
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    //上传图片验证
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
        // 获取表格数据
    getTabelPage() {

      this.total = 2;
    },
    // 表格行样式回调
    tableRowClassName({ row, rowIndex }) {
      row.rowIndex = rowIndex + 1;
    },
    //
    _page(val) {
      this.searchParams.pageNo = val;
      this.getTabelPage();
    },
    _pageSize(val) {
      this.searchParams.pageSize = val;
      this.getTabelPage();
    },
    preview(row){},
    del(row){},

    //
  },
  watch: {

  },

}
</script>
<style scoped>
.collectAddMain {
  background: var(--form-bg-a);
  border: 1px solid var(--bigborder-color);
  padding: 30px;
  box-sizing: border-box;
  margin-top: 5px;
  height: calc(100vh - 154px);
}

.form-box-1 {
  padding: 10px;
  padding-right: 50px;
  padding-bottom: 0;
}

.form-item-box {
  margin-top: 10px;
}

.btnBox {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--bigborder-color);
  padding: 10px;
  box-sizing: border-box;
  margin-top: 15px;
  background: var(--form-bg-a);
}

.submitBtn {
  margin-right: 20px;
}


/* 图标上传 */
.avatar-uploader ::v-deep .el-upload {
  border: 1px dashed var(--bigborder-color);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

::v-deep .avatar-uploader-icon {
  font-size: 16px;
  color: #8c939d;
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
}

.avatar {
  width: 40px;
  height: 40px;
  display: block;
}

.form-box-2 {
  border: 1px dashed var(--bigborder-color);
}

.collectBtnBox {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  background: var(--form-bg-a);
  border: 1px solid var(--bigborder-color);
}
</style>